package com.saurshaz.quickfixj.engine;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import quickfix.Acceptor;
import quickfix.Application;
import quickfix.ConfigError;
import quickfix.DefaultMessageFactory;
import quickfix.FileLogFactory;
import quickfix.FileStoreFactory;
import quickfix.LogFactory;
import quickfix.MessageStoreFactory;
import quickfix.SessionSettings;
import quickfix.SocketAcceptor;

public class StarterEngine{
	
	public static void main(String[] args) {
		if (args.length != 1)
			return;
		String fileName = args[0];

		// FooApplication is your class that implements the Application
		// interface
		Application recApplication = new RecipientApplication();

		SessionSettings settings;
		try {
			settings = new SessionSettings(new FileInputStream(fileName));
			MessageStoreFactory storeFactory = new FileStoreFactory(settings);
			LogFactory logFactory = new FileLogFactory(settings);
			DefaultMessageFactory messageFactory = new DefaultMessageFactory();
			Acceptor acceptor = new SocketAcceptor(recApplication, storeFactory,
					settings, logFactory, messageFactory);
			acceptor.start();
			// while( condition == true ) { do something; }
			acceptor.stop();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ConfigError e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
